package org.funny.machine32.hardware.common;

import com.google.common.collect.Maps;

import java.util.Map;

public class MachineState {

    private Map<String, IHardwareComponent> components = Maps.newHashMap();

    private boolean halt;

    public Map<String, IHardwareComponent> getComponents() {
        return components;
    }

    public void setComponents(Map<String, IHardwareComponent> components) {
        this.components = components;
    }

    public void addComponent(String componentName, IHardwareComponent component) {
        components.put(componentName, component);
    }

    public IHardwareComponent getComponent(String componentName) {
        return components.get(componentName);
    }

    public <T> T getComponent(Class<T> clazz) {
        return (T)components.get(HardwareComponentEnum.getComponentName(clazz));
    }

    public boolean isHalt() {
        return halt;
    }

    public void setHalt(boolean halt) {
        this.halt = halt;
    }

    public void reset() {
        for (IHardwareComponent component : components.values()) {
            component.reset();
        }
        halt = false;
    }
}
